import "font-awesome/css/font-awesome.min.css"
import "element-plus/theme-chalk/index.css"
import "@/assets/css/index.css"
import {library} from '@fortawesome/fontawesome-svg-core'
import {fas} from '@fortawesome/free-solid-svg-icons'
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome'
import App from "./App";
import {createApp} from "vue";
import ElementPlus from "element-plus";
import router from "./router";
import store from "./store";
// 在 main.js 中引入
import axios from "axios";
import {warning} from "./utils/message";
//import {getToken} from "./utils/auth";
library.add(fas)
// let locale =undefined;
// //控制 element-plus 组件语言
// if(I18n.global.fallbackLocale == 'zh') {
//     locale = ZhLocale;
// } else {
//     locale = EhLocale;
// }
// window.UEDITOR_HOME_URL = "/editor";
const app = createApp(App)
app.component("font-awesome-icon", FontAwesomeIcon);
app.use(router).use(store).use(ElementPlus);
/**
 * 处理未捕获异常
 * @param err
 * @param instance
 * @param info
 */
// app.config.errorHandler=(err, instance, info) => {
//     console.log(err);
//     console.log(instance);
//     console.log(info);
// }
/**
 * 处理警告
 * @param err
 * @param instance
 * @param info
 */
// app.config.warnHandler=(msg, instance, trace)=>{
//     console.log(msg);
//     console.log(instance);
//     console.log(trace);
// }
let msgOperation = function (code, msg) {
    if (code == 504 || code == 404) {
        warning('未找到对应接口');
    } else if (code == 403) {
        warning("权限不足，请联系管理员！");
    } else if (code == 401) {
        warning('尚未登录或登录超时,请登录!');
        router.replace('/login')
    } else {
        if (msg) {
            warning(msg);
        } else {
            warning('未知错误！！！！');
        }
    }
};
// axios.interceptors.request.use(req => {
//     console.log(req);
//     let url = req.url;
//     if (url.indexOf("?") != -1) {
//         url = url + "&token=" + getToken();
//     } else {
//         url = url + "?token=" + getToken();
//     }
//     req.url=url;
//     return req;
// });
/**
 * 返回错误拦截
 */
axios.interceptors.response.use(response => {
    let redata = response.data;
    if (redata.code !== 200) {
        msgOperation(redata.code, redata.cnMessage)
    }
    return response;
}, error => {
    msgOperation(error.response.status, error.response.data.cnMessage)
});
app.mount('#app');

